"use client"
import React from 'react';
// import axios from 'axios';
import { Table, Button, Popconfirm } from "antd";
import DelectStudentButton from './DelectStudentButton'
// import NewStudentButton from 'NewStudentButton'

import Link from 'next/link';
const StudentManager=async({students})=>{

    //若students是单个对象，则将其转换为数组
    const dataSource=Array.isArray(students)?students:[students]
    console.log("进入了学生管理列表")
    console.log("StudentManager",dataSource)
    const colums = [
        {
          title:"ID",
          dataIndex:"id",
          key:"id"
        },
        {
          title:"name",
          dataIndex:"name",
          key:"name"
        },
       
        {
          title:"操作",
        //   dataIndex:"status",
          key:"action",
          render:(_,row)=>(
        <div style={{display:"flex"}}>
       <Link href={`/studentManage/${row.id}`}>
        <Button>修改</Button>
        </Link> 
        {/* <Button>修改</Button> */}
        <Popconfirm title="确定要删除吗?" >
            {/* <Button>删除</Button> */}
            <DelectStudentButton id={row.id}/>
        </Popconfirm>
        
        </div>
          )
        },
       
    ];
    
    //   return <Table  columns={colums} dataSource={students} />;
    return(
        <div>
            <h1> 学生列表
                {/* <Button type="primary"size='small' href="/courses">
                    新增
                </Button> */}
            {/* <NewStudentButton/> */}
           
            <Table  columns={colums} dataSource={dataSource} />
            </h1>
        </div>
    )
}

export default StudentManager;